import { h, Component } from 'preact';
import s from './style';
import classNames from 'classnames';
import {connect} from 'preact-redux';
import history from '~/core/history';
class Invite extends Component {
	constructor(props) {
		super(props);
	}
	onInvite = () => {
		const { entrance, dispatch } = this.props;
		const { subscribe } = entrance || {};
		if (subscribe === 0) {
			dispatch({type:'openAttention'});
		} else {
			history.push('/postCard');
		}
	}
	render() {

		const { recommendTotal } = this.props;
		const {onInvite} = this;
		const bigRedClass = classNames(s.big,s.red);
		const paddingRedClass = classNames(s.padding,s.red);
		return (
			<div className={s.inviteBox}>
				<button className={s.inviteButton} onClick={onInvite} >立即邀请朋友</button>
				<div className={s.inviteInfo}>
					<div className={s.line}></div>
					<div>首次邀请送
					<span className={paddingRedClass}>100</span>
					积分/5人可
					<span className={s.red}>抽奖</span>
					</div>
					<div className={s.invited}>已邀请
						<span className={bigRedClass}>{recommendTotal}</span>
						位
					</div>
					<div className={s.line}></div>
				</div>
			</div>
		);
	}
}

const mapStateToProps = (state, ownProps) => {
	return state;
};
export default connect(mapStateToProps)(Invite);
